<template>
  <div class="login">
    <div class="login-logo">
      <div class="container">
        <a href="/#/index"><img src="/imgs/login-logo.png" alt="" /></a>
      </div>
    </div>

    <div class="wrapper">
      <div class="container">
        <div class="login-form">
          <h3>
            <span class="checked">帐号登录</span><span class="sep-line">|</span
            ><span>扫码登录</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入帐号" v-model="username"/>
          </div>
          <div class="input">
            <input type="password" placeholder="请输入密码" v-model="password"/>
          </div>
          <div class="btn-box">
            <a href="javascript:;" class="login-btn" @click="login">登录</a>
          </div>
          <div class="tips">
            <div class="sms" >手机短信登录/注册</div>
            <!-- <div class="reg">首次登录将创建新的账号</div> -->
            <div class="reg" @click="register">立即注册<span>|</span>忘记密码？</div>
          </div>
        </div>
      </div>
    </div>
<reg-footer></reg-footer>
  </div>
</template>

<script>
import RegFooter from '../components/CopyFooter'
export default {
  data () {
    return {
      username: 'jack',
      test: this.$store.state.username,
      password: 'jack',
      useId: ''

    }
  },
  created () {
    if (this.$cookie.get('username') && this.$cookie.get('password')) {
      this.username = this.$cookie.get('username')
      this.password = this.$cookie.get('password')
      // console.log('密码是：' + this.$cookie.get('password'))
    }
  },
  components: {
    RegFooter
  },
  methods: {

    login () {
      const { username, password } = this
      this.$http.post('/api/user/login', {
        username,
        password
      }).then(res => {
        // 存储cookie
        this.$cookie.set('userId', res.id, { expires: '1M' })
        // 利用vuex存储用户名
        this.$store.dispatch('saveUserName', username)
        // 跳转到首页
        this.$router.push('/index')
      })
    },
    register () {
      this.$router.push('/regiest')
    }
  }

}
</script>

<style lang="scss">
.login {
  .login-logo {
    width: 100%;
    height: 113px;
    background-color: #fff;
    .container {
      img {
        width: auto;
        height: 100%;
      }
    }
  }

  .wrapper {
    background: url('/imgs/login-bg.jpg') no-repeat center;
    .container {
      height: 576px;
      position: relative;
      .login-form {
        box-sizing: border-box;
        padding-left: 31px;
        padding-right: 31px;
        width: 410px;
        height: 510px;
        background-color: #ffffff;
        position: absolute;
        bottom: 29px;
        right: 0;
        h3 {
          line-height: 23px;
          font-size: 24px;
          text-align: center;
          font-family: Helvetica, arial, 'MI Lan Pro', 'Hiragino Sans GB',
            'PingFang SC', 'Microsoft YaHei', 微軟正黑體, '儷黑 Pro', sans-serif;
          margin: 40px auto 49px;
          color: rgb(102, 102, 102);
          font-weight: 400;
          .checked {
            color: #ff6600;
          }
          .sep-line {
            margin: 0 32px;
          }
        }
        .input {
          display: inline-block;
          width: 348px;
          height: 50px;
          border: 1px solid #e5e5e5;
          margin-bottom: 20px;
          input {
            width: 100%;
            height: 100%;
            border: none;
            padding: 18px;
          }
        }
        .btn-box {
          a.login-btn {
            display: block;
            width: 100%;
            line-height: 50px;
            margin-top: 10px;
            font-size: 16px;
            background-color: #ff6600;
            text-align: center;
            color: #fff;
          }
        }
        .tips {
          margin-top: 14px;
          font-size: 14px;
          text-align: center;
          cursor: pointer;
          .sms {
            color: #ff6600;
            margin-bottom: 20px;
            word-spacing: 200%;
          }
          .reg {
            color: #999999;
            span {
              margin: 0 7px;
            }
          }
        }
      }
    }
  }

}
</style>
